package com.ita.servlet.merchant;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ita.httpclient.CheckClient;
import com.ita.pojo.Merchant;
import com.ita.redis.MerchantBlockFactory;
import com.ita.util.Constant;
import com.ita.util.JsonUtil;
import com.ita.util.State;
import com.ita.vo.JsonResult;

@WebServlet("/sec/block/get")
public class GetBlockServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public GetBlockServlet() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		
		HttpSession session = request.getSession();
		Merchant m = (Merchant) session.getAttribute("m");
		CheckClient client = new CheckClient(m.getId());
		client.getState();
		PrintWriter writer = response.getWriter();
		String id = request.getParameter("mid");
		Merchant merchant = MerchantBlockFactory.getMerchant(id);
		System.out.println(merchant.toString());
		JsonResult jsResult=new JsonResult();
		jsResult.setCode(Constant.SUCCESS);
//		if(merchant==null){
//			jsResult.setCode(Constant.FAIL);
//		}
		jsResult.setData(merchant);
		String json = JsonUtil.getJsonFromObject(jsResult);
		writer.write(json);

	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		doGet(request, response);
	}

}
